#include "catch.hpp"

#include "common/digest.h"


using namespace std;
using namespace evm;

TEST_CASE("digest tests", "[digest]") {

    string message = "Hello, I'm a boy. My name is EVM.";
    WARN("message: " + message);

    {
        auto d = md5();
        d.update(message);
        REQUIRE(d.digest() == d.digest());
        REQUIRE(d.digest().size() == 16);
        REQUIRE(d.hexdigest() == d.hexdigest());
        REQUIRE(d.hexdigest().size() == 32);
        WARN("md5: " + d.hexdigest());
    }

    {
        auto d = sha1();
        d.update(message);
        REQUIRE(d.digest() == d.digest());
        REQUIRE(d.digest().size() == 20);
        REQUIRE(d.hexdigest() == d.hexdigest());
        REQUIRE(d.hexdigest().size() == 40);
        WARN("sha1: " + d.hexdigest());
    }

    {
        auto d = sha256();
        d.update(message);
        REQUIRE(d.digest() == d.digest());
        REQUIRE(d.digest().size() == 32);
        REQUIRE(d.hexdigest() == d.hexdigest());
        REQUIRE(d.hexdigest().size() == 64);
        WARN("sha256: " + d.hexdigest());
    }

    {
        auto d = sha512();
        d.update(message);
        REQUIRE(d.digest() == d.digest());
        REQUIRE(d.digest().size() == 64);
        REQUIRE(d.hexdigest() == d.hexdigest());
        REQUIRE(d.hexdigest().size() == 128);
        WARN("sha512: " + d.hexdigest());
    }

}
